home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue47 / IntBase / UnitAttachDB.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-04-23  |  1.8 KB  |  89 lines

  1. unit UnitAttachDB;
  2. (************************************************************************
  3.   This example demonstrates how to use 
  4.   the IBStartupParams object, 
  5.   the BuildPBnnnnnnn calls to build a Database Parameter Block, 
  6.   attaching to a database and 
  7.   closing the connection.
  8. *************************************************************************)
  9. interface
  10.  
  11. uses SysUtils, frs_Ibase, frs_Ibase_Object, frs_IBStartParams;
  12.  
  13. Procedure Open;
  14. procedure Close;
  15.  
  16. implementation
  17.  
  18. procedure SetCoreDetails;
  19. //Do the basic stuff - get the database name, username and password
  20. var
  21.   UserName: String;
  22.   Password: String;
  23. begin
  24.  
  25.   //get dbname etc.
  26.   with IBStartupParams do begin
  27.     frs_GDS.DBName:=IBDatabase;
  28.     UserName:=IBUsername;
  29.     Password:=IBPassword;
  30.   end;
  31.  
  32.   //build dpb
  33.   with frs_GDS do begin
  34.     BuildPBString(FDPB,FDPBLen,isc_dpb_user_name,Username);
  35.     BuildPBString(FDPB,FDPBLen,isc_dpb_password,Password);
  36.   end;
  37. end;
  38.  
  39. procedure SetBuffers;
  40. var
  41.   i: Integer;
  42. begin
  43.   with IBStartUpParams, frs_GDS do begin
  44.     i:=IBBuffers;
  45.     if i>0 then
  46.       BuildPBInteger(FDPB,FDPBLen,isc_dpb_num_buffers,i);
  47.   end;
  48. end;
  49.  
  50. procedure SetRole;
  51. var
  52.   Role: String;
  53. begin
  54.   with IBStartUpParams, frs_GDS do begin
  55.     Role:=IBRole;
  56.     if Role<>'' then
  57.       BuildPBString(FDPB,FDPBLen,isc_dpb_sql_role_name,Role);
  58.   end;
  59. end;
  60.  
  61. procedure SetCharSet;
  62. var
  63.   CharSet: String;
  64. begin
  65.   with IBStartUpParams, frs_GDS do begin
  66.     CharSet:=IBCharSet;
  67.     if CharSet<>'' then
  68.       BuildPBString(FDPB,FDPBLen,isc_dpb_lc_ctype,CharSet);
  69.   end;
  70. end;
  71.  
  72. procedure Open;
  73. begin
  74.   SetCoreDetails;
  75.   SetRole;
  76.   SetCharSet;
  77.   
  78.   SetBuffers;
  79.     
  80.   frs_GDS.DatabaseOpen;
  81. end;
  82.  
  83. procedure Close;
  84. begin
  85.   frs_GDS.DatabaseClose;
  86. end;
  87.  
  88. end.
  89.